package com.chencs.biz.category.service;

import com.alibaba.fastjson.JSON;
import com.chencs.biz.category.mapper.CategoryMapper;
import com.chencs.vo.biz.category.CategoryItemModel;
import com.chencs.vo.biz.category.CategoryModel;
import com.chencs.vo.biz.category.TaoBaoCategoryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by fangzehua on 2017/7/4.
 */
@Service
@Transactional
public class CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 获取分类列表
     * @return
     */
    public List<CategoryModel> getCategoryList(){
        return categoryMapper.getCategoryList();
    }


    /**
     * 添加分类
     * @param model
     * @return
     */
    public boolean insertCategory(CategoryModel model){
        try{
            categoryMapper.insertCategory(model);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    /**
     * 分类详情
     * @param id
     * @return
     */
    public CategoryModel findCategoryById(String id){

        return categoryMapper.findCategoryById(id);
    }

    /**
     * 修改分類
     * @param categoryModel
     */
    public  void updateCategory(CategoryModel categoryModel){
        System.out.println(JSON.toJSON(categoryModel));
        categoryMapper.updateCategory(categoryModel);
    }


    /**
     * 获取淘寶分类列表
     * @return
     */
    public List<TaoBaoCategoryModel> getTaoBaoCategoryList(){
        return categoryMapper.getTaoBaoCategoryList();
    }

    /**
     * 刪除淘寶分類
     */
    public void delTaoBaoCategoryById(String id){
         categoryMapper.delTaoBaoCategoryById(id);
    }



    /**
     * 取出小分类
     * @param cid
     * @return
     */
    public  List<CategoryItemModel> getCategoryItemByCid(String cid){
        return  categoryMapper.getCategoryItemByCid(cid);
    }

    /**
     * 添加小分類
     * @param model
     * @return
     */
    public boolean insertCategoryItem(CategoryItemModel model){
        try{
            System.out.println(JSON.toJSON(model));
            categoryMapper.insertCategoryItem(model);
            return true;
        }catch (Exception e){
            return false;
        }
    }


    public boolean updateCategoryItem(CategoryItemModel model){
        try{
            categoryMapper.updateCategoryItem(model);
            return true;
        }catch (Exception e){
            return false;
        }
    }


    public CategoryItemModel findCategoryItemModelById (String id){

        return categoryMapper.findCategoryItemModelById(id);

    }
}

